﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.user
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }           
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtzu_id.Text.Trim().Length==0)
			{
				strErr+="zu_id不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtzc_id.Text))
			{
				strErr+="zc_id格式错误！\\n";	
			}
			if(this.txtzu_name.Text.Trim().Length==0)
			{
				strErr+="zu_name不能为空！\\n";	
			}
			if(this.txtzu_pwd.Text.Trim().Length==0)
			{
				strErr+="zu_pwd不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtzu_sex.Text))
			{
				strErr+="zu_sex格式错误！\\n";	
			}
			if(this.txtzu_roles.Text.Trim().Length==0)
			{
				strErr+="zu_roles不能为空！\\n";	
			}
			if(this.txtzu_weixin.Text.Trim().Length==0)
			{
				strErr+="zu_weixin不能为空！\\n";	
			}
			if(this.txtzu_qq.Text.Trim().Length==0)
			{
				strErr+="zu_qq不能为空！\\n";	
			}
			if(this.txtzu_tel.Text.Trim().Length==0)
			{
				strErr+="zu_tel不能为空！\\n";	
			}
			if(this.txtzu_email.Text.Trim().Length==0)
			{
				strErr+="zu_email不能为空！\\n";	
			}
			
			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string zu_id=this.txtzu_id.Text;
			int zc_id=int.Parse(this.txtzc_id.Text);
			string zu_name=this.txtzu_name.Text;
			string zu_pwd=this.txtzu_pwd.Text;
			int zu_sex=int.Parse(this.txtzu_sex.Text);
			string zu_roles=this.txtzu_roles.Text;
			string zu_weixin=this.txtzu_weixin.Text;
			string zu_qq=this.txtzu_qq.Text;
			string zu_tel=this.txtzu_tel.Text;
			string zu_email=this.txtzu_email.Text;

			Chizx.Model.UserModel model=new Chizx.Model.UserModel();
			model.zu_id=zu_id;
			model.zc_id=zc_id;
			model.zu_name=zu_name;
			model.zu_pwd=zu_pwd;
			model.zu_sex=zu_sex;
			model.zu_roles=zu_roles;
			model.zu_weixin=zu_weixin;
			model.zu_qq=zu_qq;
			model.zu_tel=zu_tel;
			model.zu_email=zu_email;
            model.zu_lastdate = "从未登录";
            model.zu_lastip =  "从未登录";
            model.zu_createdate = Chizx.Common.DateHelper.getUtcNow();
            model.zu_status = "u0";
            model.zu_direct = "00";//指导老师默认为未分配
           
            //写入系统日志
            if (Session["UserEntity"] == null)
            {
                Response.Redirect("/e/Login.aspx");
            }
            else
            {
                Chizx.BLL.UserBll bll = new Chizx.BLL.UserBll();
                bll.Add(model);
                Chizx.Model.UserModel sbmmodel = (Chizx.Model.UserModel)Session["UserEntity"];
                Chizx.BLL.SystemLogBll sbll = new Chizx.BLL.SystemLogBll();
                Chizx.Model.SystemLogModel slm = new Chizx.Model.SystemLogModel();
                slm.zu_id = sbmmodel.zu_id;
                slm.zl_dowhen = DateTime.Now;
                slm.zl_dowhat = "添加用户";
                slm.zl_dotype = "3";//0:Test,1:Auth,2:Read,3:Write,4:Del,5:Inpor
                slm.zl_dodesc = "操作成功";
                sbll.Add(slm);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");
            }
			

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
